package com.innerex.inexclear.core.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.innerex.inexclear.core.dao.ClearingTransactionDao;
import com.innerex.inexclear.core.model.ClearingTransaction;

/**
 * This class interacts with Spring's HibernateTemplate to save/delete and - *
 * retrieve Transaction objects.
 * 
 * @author <a href="mailto:evencia@innerex.com"> Edoardo Vencia
 *         (evencia@innerex.com)</a>
 */
@Repository
public class ClearingTransactionDaoHibernate extends
		GenericDaoHibernate<ClearingTransaction, Long> implements ClearingTransactionDao {

	/**
	 * Constructor to create a Generics-based version using Order as the entity
	 */
	public ClearingTransactionDaoHibernate() {
		super(ClearingTransaction.class);
	}

	public ClearingTransaction getClearingTransactionByProduct(String product) {
		List clearingTransactions = getHibernateTemplate().find(
				"from ClearingTransaction where product=?", product);

		if (clearingTransactions.isEmpty()) {
			return null;
		} else {
			return (ClearingTransaction) clearingTransactions.get(0);
		}
	}
}
